.text
.section .rodata
.align 3
.LC0:
        .string "Please enter an integer to be summed "
        .align  3
.LC1:
        .string "(q to quit): "
        .align  3
.LC2:
        .string "%ld"
        .align  3
.LC3:
        .string "Please enter next integer (q to quit): "

.text
.align 2
.globl main
.type main, @function
main:
    addi sp, sp, -48
    sd ra, 40(sp)
    sd s0, 32(sp)

    // sum
    sd zero, -24(s0)

    lui a5, %hi(.LC0)
    addi a0, a5, %lo(.LC0)
    call printf

    lui a5, %hi(.LC1)
    addi a0, a5, %lo(.LC1)
    call printf

    // &num
    addi a1, s0, -32
    lui a5, %hi(.LC2)
    addi a0, a5, %lo(.LC2)
    call scanf
    // status
    sw a0, -36(s0)
    j .L2

.L5:
    ld a5, -32(s0)
    ld a4, -24(s0)
    add a5, a4, a5
    sd a5, -24(s0)

    lui a5, %hi(.LC3)
    addi a0, a5, %lo(.LC3)
    call printf

    addi a1, s0, -32
    lui a5, %hi(.LC2)
    addi a0, a5, %lo(.LC2)
    call scanf
    sw a0, -36(s0)
.L2:
    li a0, 1
    sd a0, -36(s0)
    j .L5

// 以下这几句是我加的，其实编译器生成的汇编没有
/*
    ld ra, 40(sp)
    ld s0, 32(sp)
    addi sp, sp, 48
    jr ra
*/